package com.gis.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gis.bean.User;
import com.gis.dao.UserDao;
import com.gis.util.PageResult;
import com.gis.util.ResponseUtil;

@WebServlet("/user/page")
public class UserPageServlet extends HttpServlet {
	UserDao userDao = new UserDao();

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String pageSize = req.getParameter("rows");
		if(pageSize == null) {
			pageSize = "5";
		}
		String pageNum = req.getParameter("page");
		if(pageNum == null) {
			pageNum = "1";
		}
		Integer size = Integer.parseInt(pageSize);
		Integer num = Integer.parseInt(pageNum);

		PageResult<User> pageResult = userDao.listUser((num - 1) * size, size);
		ResponseUtil.writePage(resp, pageResult);
	}
	

}
